package com.mf.basic.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mf.basic.debounces.Debounce;
import com.mf.basic.entity.DtoSet;
import com.mf.basic.log_api.LogApi;
import com.mf.basic.rs.ResponseResult;
import com.mf.basic.services.ServiceSet;
import com.mf.basic.utils.MyAssert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by Luke on 2025/3/7 16:58.
 */
@RestController
@ResponseResult
@SaCheckLogin
@RequestMapping("/set")
public class ControllerSet implements MyAssert {

    @Resource
    private ServiceSet serviceSet;

    /**
     * 保存设置值
     * @param set id,setValue,remark,showOrder
     */
    @Debounce
    @LogApi("设置-保存")
    @PostMapping("/save")
    @SaCheckPermission("set.save")
    public void register(@RequestBody DtoSet set) {
        idIsNull(set.getId(), "ID");
        strIsNull(set.getSetValue(), "设置值");
        serviceSet.doSave(set);
    }

    /**
     * 查询设置值
     * @param params setKey
     * @return IPage<DtoRole>
     */
    @Debounce
    @PostMapping("/list")
    @SaCheckPermission("set.search")
    public Map<String, DtoSet> get(@RequestBody Map<String, Object> params) {
        return serviceSet.findBySetKey(params.get("setKey") + "");
    }

    /**
     * 分页查询
     * @param params pageNum,pageSize
     * @return IPage<DtoSet>
     */
    @GetMapping("/page")
    @SaCheckPermission("set.search")
    public IPage<DtoSet> page(@RequestBody Map<String, Object> params){
        pageIsNull(params);
        return serviceSet.findPageByParams(params);
    }

}
